(function () {
  let pageNum = 0;
  getDate(pageNum);
  //遍历页码,并渲染
  let opt = '';
  for (let index = 0; index < 14; index++) {
      opt += `
      <option value="${index}">${index+1}</option>
      `
  };
  $('#number').html(opt);
  //事件函数
  $('#prev').on('click', function () {
      pageNum--;
      $('#number')[0].value = pageNum;
      isRequest(pageNum);
  });
  $('#next').on('click', function () {
      pageNum++;
      $('#number')[0].value = pageNum;
      isRequest(pageNum)
  });
  $('#number').on('change', function () {
      pageNum = this.value;
      isRequest(pageNum)
  });
  //判断是否调用请求
  function isRequest(num) {
      if (num < 0) {
          $('#prev').attr('disabled', true);
          $('#number')[0].value = 0;
      } else if (num > 13) {
          $('#next').attr('disabled', true);
          $('#number')[0].value = 13;
      } else {
          $('#prev').attr('disabled', false)
          $('#next').attr('disabled', false)
          getDate(num);
      }

  }
  //下拉框监听事件

  function getDate(index = 0) {
      let ul = document.querySelector("#product>ul")
      index -= 0;
      fetch('http://chst.vip:1234/api/getmoneyctrl?pageid=' + index).then(body => body.json()).then(res => {
          let result = res.result;
          console.log(result);
          let str = '';
          result.map(items => {
              let regExp = /(?<=imgurl=)[^'"]*/;
              let mate = items.productImg2.match(regExp);
              str += `
              <li>
              <a>
                 <div> <img src=${mate[0]} productid=${items.productId}></div>
                  
                  <div id="wz">
                  <h4>${items.productName}<span>${items.productPinkage}<span/></h4>
                  <span>${items.productFrom}${'|'}
                      ${items.productTime}</span>
                      <b>${items.productComCount}</b>
                  </div>
                  </a>
              </li>`
          });
          ul.innerHTML = str
      })
      ul.onclick = function (e) {
          if (e.target.localName === "img") {
              let _this = e.target
              let id = _this.getAttribute("productid")
              console.log(id);
              location.href = "/移动端项目/项目基本结构/html/product.html?productid=" + id
          }
      }
  };

})()